﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;

namespace QXBook.Handlers.AjaxHandlers
{
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
    public class AjaxMappingAttribute : System.Attribute
    {
        /// <summary>
        /// 参数名称
        /// </summary>
        public string ParamName { get; set; }
        /// <summary>
        /// 是否必须
        /// </summary>
        public bool IsRequired { get; set; }
        //构造函数
        public AjaxMappingAttribute() : this(null, false) { }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="paramName"></param>
        /// <param name="isRequired"></param>
        public AjaxMappingAttribute(string paramName, bool isRequired)
        {
            this.ParamName = paramName;
            this.IsRequired = isRequired;
        }
        /// <summary>
        /// 绑定参数
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="param"></param>
        public static void Bind(object obj, NameValueCollection param)
        {
            AjaxMappinger.Mapping<AjaxMappingAttribute>(obj, (paramName, mt) =>
            {
                return param[paramName];
            });
        }
    }
}
